﻿@model DHQGHN.PM2.Models.Online.Khaisinh2Model
<style>
    .ui-tooltip, .arrow:after {
        background: #FAFAD2;
    }

    .ui-tooltip {
        color: black;
        font-size: 12px;
    }

    .arrow {
        width: 70px;
        height: 16px;
        overflow: hidden;
        position: absolute;
        left: 50%;
        margin-left: -35px;
        bottom: -16px;
    }

        .arrow.top {
            top: -16px;
            bottom: auto;
        }

        .arrow.left {
            left: 20%;
        }

        .arrow:after {
            content: "";
            position: absolute;
            left: 20px;
            top: -20px;
            width: 25px;
            height: 25px;
            box-shadow: 6px 5px 9px -9px black;
            -webkit-transform: rotate(45deg);
            -ms-transform: rotate(45deg);
            transform: rotate(45deg);
        }

        .arrow.top:after {
            bottom: -20px;
            top: auto;
        }
</style>
<script>
    @functions{
        public string GetAntiForgeryToken()
        {
            string cookieToken, formToken;
            AntiForgery.GetTokens(null, out cookieToken, out formToken);
            return cookieToken + "," + formToken;
        }
    }
    $('.mnResident #mainForm').setMask("Đang thực hiện...");
    jQuery(function ($) {
        Tooltip();
        var dem = 0;
        var total = 2;
        checkhtml();
        Checkngay("DAYKS2");
        Checkthang("MONTHKS2");
        Checknam("YEARKS2");
        Checkcmnd("FATHER_IDCARD_NUM");
        codedob = $("#CODEDOB").val();
        tinhdob = $("#CODEDOB").val().substring(0, 2);
        huyennpdob = $("#CODEDOB").val().substring(0, 5);
        if (codedob != "") {
            $("#TINHKS2").val(tinhdob);
            total++;
        }
        if ($("#TINHKS2").val() != "-1") {
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")',
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#TINHKS2").val(),
                    level: '2'
                },
                success: function (states) {
                    $("#HUYENKS2").append('<option value="' + '-1' + '">' +
                 '-- Chọn Huyện --' + '</option>');
                    $.each(states, function (i, state) {
                        $("#HUYENKS2").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');
                    });

                },
                complete: function () {
                    $("#HUYENKS2").val(huyennpdob);
                    $("#XAKS2").empty();
                    $("#XAKS2").append('<option value="' + '-1' + '">' +
                        '-- Chọn Xã --' + '</option>');
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Action("GetAdministrativeUnit1")',
                        headers: {
                            'VerificationToken': '@GetAntiForgeryToken()'
                        },
                        dataType: 'json',

                        data: {
                            code: $("#HUYENKS2").val(),
                            level: '3'
                        },

                        success: function (states) {

                            $.each(states, function (i, state) {
                                $("#XAKS2").append('<option value="' + state.Value + '">' +
                                    state.Text + '</option>');

                            });

                        },
                        complete: function () {
                            $("#XAKS2").val(codedob);
                            dem++;
                            checkloading(dem, total);
                        },
                        error: function (ex) {
                            alert('Failed to retrieve states.' + ex);
                        }
                    });
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
        } else {
            $("#HUYENKS2").append('<option value="' + '-1' + '">' +
                 '-- Chọn Huyện --' + '</option>');
            $("#XAKS2").append('<option value="' + '-1' + '">' +
                 '-- Chọn Xã --' + '</option>');
        }
        $("#TINHKS2").change(function () {
            $("#divLoading").show();
            $("#HUYENKS2").empty();
            $("#XAKS2").empty();
            $("#HUYENKS2").append('<option value="' + '-1' + '">' +
                 '-- Chọn Huyện --' + '</option>');
            $("#XAKS2").append('<option value="' + '-1' + '">' +
                 '-- Chọn Xã --' + '</option>');
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")',
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#TINHKS2").val(),
                    level: '2'
                },
                success: function (states) {
                    $.each(states, function (i, state) {
                        $("#HUYENKS2").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');
                    });

                },
                complete: function (states) {
                    $("#divLoading").hide();
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
            return false;
        })
        $("#HUYENKS2").change(function () {

            $("#XAKS2").empty();
            $("#divLoading").show();
            $("#XAKS2").append('<option value="' + '-1' + '">' +
                '-- Chọn Xã --' + '</option>');
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")',
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#HUYENKS2").val(),
                    level: '3'
                },

                success: function (states) {

                    $.each(states, function (i, state) {
                        $("#XAKS2").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');


                    });

                },
                complete: function () {
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
            return false;
        });
        $.ajax({
            url: '@Url.Action("GetAllByListName")',
            dataType: 'json',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            method: 'GET',
            data: { 'tablename': 'COUNTRY' },
            success: function (data, textStatus, jqXHR) {
                $(".FATHER_COUNTRY_ID").append('<option value="">' +
               '-- Chọn Quốc tịch --' + '</option>');
                $.each(data, function (i, item) {
                    $(".FATHER_COUNTRY_ID").append('<option value="' + item.CodeID + '">' +
                         item.Name + '</option>');


                });
                $(".FATHER_COUNTRY_ID").val("@Model.FATHER_COUNTRY_ID");
            },
            complete: function () {
                dem++;
                checkloading(dem, total);
            }

        });
        $.ajax({
            url: '@Url.Action("GetAllByListName")',
            dataType: 'json',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            method: 'GET',
            data: { 'tablename': 'ETHNIC' },
            success: function (data, textStatus, jqXHR) {
                $(".FATHER_ETHNIC_ID").append('<option value="">' +
              '-- Chọn Dân tộc --' + '</option>');
                $.each(data, function (i, item) {
                    $(".FATHER_ETHNIC_ID").append('<option value="' + item.CodeID + '">' +
                         item.Name + '</option>');


                });
                $(".FATHER_ETHNIC_ID").val(@Model.FATHER_ETHNIC_ID);
            },
            complete: function () {
                dem++;
                checkloading(dem, total);
            }


        });

    });
    
    function ClickButton(Next) {
        var ngay = $("#DAYKS2").val();
        var thang = $("#MONTHKS2").val();
        var nam = $("#YEARKS2").val();
        xa = $("#XAKS2").val();
        if (xa == "-1") {
            xa = "";
        }
        var dataSend = {
            'RESIDENT_ID': $('#selectMenu').val(),
            'FATHER_LNAME': $("#FATHER_LNAME").val(),
            'FATHER_MNAME': $("#FATHER_MNAME").val(),
            'FATHER_FNAME': $("#FATHER_FNAME").val(),
            'FATHER_DOB': nam + thang + ngay,
            'FATHER_ETHNIC_ID': $(".FATHER_ETHNIC_ID").val(),
            'FATHER_COUNTRY_ID': $(".FATHER_COUNTRY_ID").val(),
            'FATHER_RPOB_ADM_UNIT_ID': xa,
            'FATHER_IDCARD_NUM': $("#FATHER_IDCARD_NUM").val(),
            'NEXT': Next,
        };
        var jqXHR = $.ajax({
            url: '@Url.Action("Khaisinh2New","Online")',
            dataType: 'html',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            method: 'post',
            cache: false,
            data: dataSend,
            success: function myfunctionSuccess(data, textStatus, jqXHR) {
                //$('#mainForm').html(data);
                if (Next != '2') {
                    $('#mainForm').html(data);
                } else {
                    window.location.href = '@Url.Action("Login","Online")';
                }
            },
            complete: function (jqXHR, textStatus) {
                if (Next == '1') {
                    $('#thongtin').text("THÔNG TIN MẸ ĐẺ");
                } else {
                    $('#thongtin').text("THÔNG TIN KHAI SINH");
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert('Có lỗi xảy ra trong quá trình lưu thông tin: ' + errorThrown);
            },

        });
    }
    $("#btnNext").click(function (event, giatri) {
        
        if (checkhtml()) {
            alert("Dữ liệu nhập không được có ký tự '<' ở đầu.");
        } else {
            if (giatri != null) {
                ClickButton(giatri);
            }
            else {
                if (Checkdatetime("DAYKS2", "MONTHKS2", "YEARKS2") == 0) {
                    $('.mnResident #mainForm').setMask("Đang thực hiện...");
                    ClickButton(1);
                }
            }
        }
    });
    $("#btnBack").click(function () {
        if (checkhtml()) {
            alert("Dữ liệu nhập không được có ký tự '<' ở đầu.");
        } else {
            $('.mnResident #mainForm').setMask("Đang thực hiện...");
            ClickButton(0);
        }
    });

</script>
<div class="row margin-top-20">
    <div class="col-md-6">
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Họ</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.FATHER_LNAME, new { @class = "form-control ", MaxLength = 50, @placeholder = "Họ" })
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Tên đệm</label>
            <div class="col-md-8 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.FATHER_MNAME, new { @class = "form-control ", MaxLength = 150, @placeholder = "Tên đệm" })
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Tên khai sinh</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.FATHER_FNAME, new { @class = "form-control ", MaxLength = 50, @placeholder = "Tên khai sinh" })
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Ngày sinh</label>
            <div class="col-md-8 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.DAYKS2, new { @class = "form-control", style = "width: 25%; display: inline;padding-left: 4%;", MaxLength = 2, @title = @Html.ToolTipMessageFor(m => m.DAYKS2) })/@Html.TextBoxFor(model => model.MONTHKS2, new { @class = "form-control", style = "width: 25%; display: inline;padding-left: 1%;", MaxLength = 2, @title = @Html.ToolTipMessageFor(m => m.MONTHKS2) })/@Html.TextBoxFor(model => model.YEARKS2, new { @class = "form-control", style = "width: 40%; display: inline;padding-left: 1%;", MaxLength = 4, @title = @Html.ToolTipMessageFor(m => m.YEARKS2) })
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Số CMND/CCCD</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                @Html.TextBoxFor(model => model.FATHER_IDCARD_NUM, new { @class = "form-control ", MaxLength = 12, @title = @Html.ToolTipMessageFor(m => m.FATHER_IDCARD_NUM) })
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Quốc tịch</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                <select class="FATHER_COUNTRY_ID form-control" ></select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Dân tộc</label>
            <div class="col-md-8 col-sm-8 col-xs-7 col-sm-8 col-xs-7">
                <select class="FATHER_ETHNIC_ID form-control "  ></select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5">Nơi ĐK khai sinh</label>
            <div class="col-md-8 col-sm-8 col-xs-7">
                @Html.DropDownList("TINHKS2", ViewData["DISTRICT_CODE"] as List<SelectListItem>, new { @class = "form-control ", @title = @Html.ToolTipMessageFor(m => m.TINH) })
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5"></label>
            <div class="col-md-8 col-sm-8 col-xs-7">
                @Html.DropDownList("HUYENKS2", new SelectList(string.Empty, "Value", "Text"), new { @class = "form-control", @title = @Html.ToolTipMessageFor(m => m.HUYEN) })
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-4 col-sm-4 col-xs-5"></label>
            <div class="col-md-8 col-sm-8 col-xs-7">
                @Html.DropDownList("XAKS2", new SelectList(string.Empty, "Value", "Text"), new { @class = "form-control", @title = @Html.ToolTipMessageFor(m => m.XA) })
            </div>
        </div>
    </div>
    <div style="text-align:center; margin-top:30px;">
        <button class="btn btn-sm" id="btnBack" style="background-color: #2664B7; color:#ffffff; min-width:100px;"><i class="fa fa-angle-double-left"></i> Quay lại</button>
        <button class="btn btn-sm" id="btnNext" style="background-color: #2664B7; color:#ffffff; min-width:100px;">Tiếp tục <i class="fa fa-angle-double-right"></i></button>
    </div>
    <div>
        @Html.HiddenFor(model => model.CODEDOB)
        @Html.HiddenFor(model => model.FATHER_COUNTRY_ID)
    </div>
</div>






